import { Behavior } from "./behavior"
import { ClickBehavior } from "./behavior-type"
export function setupClickMonitor(behavior: Behavior): void {
    document.addEventListener(
        "click",
        event => {
            const target = event.target as HTMLElement
            // 过滤掉模态框
            if (target.tagName === "BODY" || target.classList?.contains("ant-modal-wrap")) return

            const clickData: ClickBehavior = {
                category: "Click",
                type: "click",
                status: "ok",
                dom: simplefyDom(target),
                time: Date.now()
            }
            behavior.push(clickData)
        },
        true // 捕获阶段监听
    )
}

// 简化DOM信息（保持原有功能，移除调试日志）
function simplefyDom(el: HTMLElement): string {
    const tag = el.tagName.toLowerCase()
    const id = el.id ? ` id="${el.id}"` : ""
    const classes = el.className ? ` class="${el.className}"` : ""
    return `<${tag}${id}${classes}>${el.textContent?.trim() || ""}</${tag}>`
}
